package com.wyvoid.forum.web.action.forum;

import com.wyvoid.forum.web.action.BaseAction;
import com.wyvoid.forum.annotations.Secure;
import com.wyvoid.forum.service.ITopicService;
import com.wyvoid.forum.domain.Topic;
import net.sourceforge.stripes.action.*;
import net.sourceforge.stripes.integration.spring.SpringBean;

/**
 * 版主管理
 * User: cjp
 * Date: 2007-7-4
 * Time: 20:29:19
 */
@UrlBinding("/masterManage.do")
public class MasterManageAction extends BaseAction {
    @SpringBean
    private ITopicService topicService;
    private long[] topicId;
    private long fid;
    private long tid;

    public void setTopicId(long[] topicId) {
        this.topicId = topicId;
    }

    public void setTopicService(ITopicService topicService) {
        this.topicService = topicService;
    }


    public void setFid(long fid) {
        this.fid = fid;
    }

    public void setTid(long tid) {
        this.tid = tid;
    }

    @DefaultHandler
    @HandlesEvent("stick")
    @Secure(authority = "canStickPost")
    public Resolution stickTopics() {
        if (topicId != null) {
            for (long tid : topicId) {
                topicService.stickTopic(tid);
            }
        }
        return getResolution();
    }

    @HandlesEvent("delete")
    @Secure(authority = "canDeletePost")
    public Resolution deleteTopic() {
        if (topicId != null) {
            for (long tid : topicId) {
                topicService.deleteTopic(tid);
            }
        }
        return getResolution();
    }

    @HandlesEvent("move")
    @Secure(authority = "canMovePost")
    public Resolution moveTopic() {
        return null;
    }

    @HandlesEvent("type")
    @Secure(authority = "canChangeCategory")
    public Resolution typeTopic() {
        return null;
    }

    @HandlesEvent("close")
    @Secure(authority = "canOpenOrCloseTopic")
    public Resolution closeTopic() {
        return null;
    }

    @HandlesEvent("digest")
    @Secure(authority = "canDigestPost")
    public Resolution digestTopic() {
        if (topicId != null) {
            for (long tid : topicId) {
                topicService.digestTopic(tid);
            }
        }
        return getResolution();
    }

    public Resolution getResolution() {
        if (tid > 0) {
            return new RedirectResolution(TopicAction.class).addParameter("tid", tid);
        }else{
            return new RedirectResolution(ForumAction.class).addParameter("forumId", fid);
        }
    }
}
